<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<!-- Set render engine for 360 browser -->
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

	<link href="/public/simpleboot/themes/<?php echo C('SP_ADMIN_STYLE');?>/theme.min.css" rel="stylesheet">
    <link href="/public/simpleboot/css/simplebootadmin.css" rel="stylesheet">
    <link href="/public/js/artDialog/skins/default.css" rel="stylesheet" />
    <link href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome.min.css"  rel="stylesheet" type="text/css">
    <style>
		.length_3{width: 180px;}
		form .input-order{margin-bottom: 0px;padding:3px;width:40px;}
		.table-actions{margin-top: 5px; margin-bottom: 5px;padding:0px;}
		.table-list{margin-bottom: 0px;}
	</style>
	<!--[if IE 7]>
	<link rel="stylesheet" href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome-ie7.min.css">
	<![endif]-->
<script type="text/javascript">
//全局变量
var GV = {
    DIMAUB: "/",
    JS_ROOT: "public/js/",
    TOKEN: ""
};
document.domain = "xinhuiwen.com";
</script>
<!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/public/js/jquery.js"></script>
    <script src="/public/js/wind.js"></script>
    <script src="/public/js/publish.js"></script>

    <script src="/public/simpleboot/bootstrap/js/bootstrap.min.js"></script>
<?php if(APP_DEBUG): ?><style>
		#think_page_trace_open{
			z-index:9999;
		}
	</style><?php endif; ?>
<script type="text/javascript" src="/public/js/jquery.cityselect.js"></script>
</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform"  action="<?php echo U('Admin/AdminUser/editRolePost');?>">                
         <div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 90px;">一、新闻业务</label>
         	</div>
    	</div>
    	<?php  if($role_data['column_role_count'] > 0){ ?>
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;">常规栏目：</label>
            <div class="span3" style="width:800px;">
            	<?php
 foreach($role_data['column_role'] as $column_key=>$column_value){ ?>
                <input name="column_checbox[]"   type="checkbox"   value="<?php echo ($column_value["column_id"]); ?>"  <?php if(in_array($column_value['column_id'],$admin_user_column_role_data)) echo 'checked="checked" '?> /><?php echo ($column_value["name"]); ?>&nbsp;&nbsp;&nbsp;
                <?php
 } ?>
            </div>
        </div>
    	<?php  } ?>
    	
    	
    	<!-- 地区(开始) -->
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;">本地栏目</label>
            <div class="span3">
                <input type="text" style="width: 556px;" name="area" id="area" readonly="readonly" value="<?php echo $area_role_name_data ? implode(',',$area_role_name_data).',' : ''?>">
            </div>
        </div>
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
				<?php if(is_array($established_area_data)): foreach($established_area_data as $key=>$value): ?><!-- 分组(开始) -->
				<div class="span3">
				<?php  switch($key){ case 1: echo 'ABCDE'; break; case 2: echo 'FGHIJ'; break; case 3: echo 'KLMNO'; break; case 4: echo 'PQRST'; break; case 5: echo 'UVWXYZ'; break; } ?>
					<p></p>
					<!-- 拼音首字母(开始) -->
					<?php if(is_array($value)): foreach($value as $key1=>$value1): ?><div class="span3">
						<?php echo ($key1); ?>&nbsp;&nbsp;
							<div class="span3">
							<?php if(is_array($value1)): foreach($value1 as $key2=>$value2): ?><input name="area_checbox"  area_name="<?php echo ($value2["name"]); ?>" type="checkbox"   value="<?php echo ($value2["area_id"]); ?>"  <?php if(in_array($value2['area_id'],$area_role_id_data)) echo 'checked="checked" '?>/><?php echo ($value2["name"]); ?>&nbsp;&nbsp;&nbsp;<?php endforeach; endif; ?>
							</div>
						</div><?php endforeach; endif; ?>
					<!-- 拼音首字母(结束) -->
				</div>
				<!-- 分组(结束) --><?php endforeach; endif; ?>
            </div>
        </div>
    	<!-- 地区(结束) -->
    	
    	
    	<?php  if($role_data['sys_menu_role_count'] > 0){ ?>            
     	<div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 100px;"></label>
				<div class="span3" style="width:800px;">二、其他业务：
					<?php
 foreach($role_data['sys_menu_role'] as $sys_menu_key=>$sys_menu_value){ ?>
	                	<input name="sys_menu_checbox[]"   type="checkbox"   value="<?php echo ($sys_menu_value["menu_id"]); ?>"  <?php if(in_array($sys_menu_value['menu_id'],$admin_user_sys_menu_role_data)) echo 'checked="checked" '?> /><?php echo ($sys_menu_value["name"]); ?>&nbsp;&nbsp;&nbsp;
	                <?php
 } ?>
				</div>
         	</div>
    	</div>
		<?php
 } ?>

		<?php if(count($all_company) > 0){ ?>
			<div class="control-group">
				<div class="span3">
					<label class="span1 control-label" style="width: 100px;"></label>
					<div id="city_1" class="span3" style="width:800px;">三、所属公司：
						<select class="prov" name="prov"></select>
						<select class="city" name="city" id="city" disabled="disabled"></select>
						<select class="company_name" name="company_id"></select>
					</div>
				</div>
			</div>
		<?php } ?>
		<?php if(count($role_info) > 0){ ?>
		<div class="control-group">
			<div class="span3">
				<label class="span1 control-label" style="width: 100px;"></label>
				<div class="span3" style="width:800px;">四、所属角色：
					<?php
 foreach($role_info as $key=>$val){ ?>
					<input name="role_checbox[]" type="checkbox" value="<?php echo ($val["role_id"]); ?>" <?php if($val['is_checked'] == 1){ echo 'checked="checked"';}?>/><?php echo ($val["role_name"]); ?>&nbsp;&nbsp;&nbsp;
					<?php
 } ?>
				</div>
			</div>
		</div>
		<?php } ?>
        <input type="hidden" name="admin_id" id="admin_id" value="<?php echo $admin_id;?>">
		<input type="hidden" name="area_hidden_ids" id="area_hidden_ids" value="<?php echo $area_role_id_data ? implode(',',$area_role_id_data).',' : ''?>">
        <div class="form-actions" style="padding-left:260px;">
            <a class="btn btn-primary" id="ajaxform">提 交</a>
            &nbsp;&nbsp;<a class="btn" id="ajaxback"><?php echo L('BACK');?></a>
        </div>
    </form>
</div>
<script src="/public/js/common.js"></script>
<script type="text/javascript" src="/public/js/content_addtop.js"></script>
<script type="text/javascript" src="/public/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/public/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="/public/js/layer/layer.js"></script>
<script>
$(function(){
    var prov = '<?php echo ($company_info["prov"]); ?>' ? '<?php echo ($company_info["prov"]); ?>' : '北京';
    var city = '<?php echo ($company_info["city"]); ?>' ? '<?php echo ($company_info["city"]); ?>' : '东城区';
    var company_id = '<?php echo ($company_info["company_id"]); ?>';

    $("#city_1").citySelect({
        url: "/public/js/city.js",
        prov: prov, //省份
        city: city, //城市
        nodata:"none" //当子集无数据时，隐藏select
    });

    //获取默认地区下的公司
	var data = {city: city};
	$.ajax({
		url: "<?php echo U('PeopleManagement/getCompanyList');?>",
		type: "POST",
		data: data,
		dataType: 'json',
		success: function (res) {
			var str = '';
			$('.company_name').children().remove();
            str += '<option name="company" value="0">请选择</option>';
			$.each(res, function (k, v) {
				if(v.company_id){
				    if(company_id == v.company_id){
                        str += '<option name="company" selected="selected" value="'+v.company_id+'">'+v.name+'</option>';
					}else{
                        str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
					}

				}
			})
			$('.company_name').append(str);
		},

		error: function () {
			alert('网络异常，请检查网络后重试');
		}
	});

    $('#city').change( function () {
        var city = $('#city').val();
        $.ajax({
            url: "<?php echo U('PeopleManagement/getCompanyList');?>",
            type: "POST",
            data: {city: city},
            dataType: 'json',
            success: function (res) {
                var str = '';
                $('.company_name').children().remove();
                $.each(res, function (k, v) {
                    if(v.company_id){
                        str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                    }
                })
                $('.company_name').append(str);
            },

            error: function () {
                alert('网络异常，请检查网络后重试');
            }
        });
    })

    $('.prov').bind('change', function () {
        setTimeout(function () {
            var city = $('#city').val();
            if(!city){return false}
            $.ajax({
                url: "<?php echo U('PeopleManagement/getCompanyList');?>",
                type: "POST",
                data: {city: city},
                dataType: 'json',
                success: function (res) {
                    var str = '';
                    $('.company_name').children().remove();
                    $.each(res, function (k, v) {
                        if(v.company_id){
                            str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                        }
                    })
                    $('.company_name').append(str);
                },

                error: function () {
                    alert('网络异常，请检查网络后重试');
                }
            });
        }, 50)
    })


	$("[name='area_checbox']").click(function(){
		var area_id = $(this).val();
		var area_name = $(this).attr('area_name');
		
		var area_hidden_ids = $("#area_hidden_ids").val();
		var area_values = $("#area").val();
		
		var ids_arr = area_hidden_ids.split(",");          
		var values_arr = area_values.split(",");   
		
		if(ids_arr.indexOf(area_id) == '-1'){
			area_hidden_ids+=area_id+',';
			area_values+=area_name+',';
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==area_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			area_hidden_ids = ids_arr.join(",");
			area_values = values_arr.join(",");
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}
	})
})


// ajax 提交表单
$(document).ready(function(){
    $("#ajaxform").click(function(){    // 提交按钮触发事件
    	//获取新闻业务和其他业务的选中值
    	var boxes = $("[name='column_checbox[]']");
    	var boxes1 = $("[name='sys_menu_checbox[]']");
    	var role = $("[name='role_checbox[]']");
		var role_list = [];
        var column_checbox = [];
        var sys_menu_checbox = [],
			company_id = $('.company_name').val();

        for(i=0;i<boxes.length;i++){
            if(boxes[i].checked == true){
            	column_checbox.push(boxes[i].value);
            }
        }
        for(i=0;i<boxes1.length;i++){
            if(boxes1[i].checked == true){
            	sys_menu_checbox.push(boxes1[i].value);
            }
        }

		for(i=0;i<role.length;i++){
			if(role[i].checked == true){
				role_list.push(role[i].value);
			}
		}

        var tourl = $("#myform").attr("action");    // 获取 表单的 提交地址
        var admin_id = $("#admin_id").val();
        var area_hidden_ids = $("#area_hidden_ids").val();

        $.post(tourl,{
        	column_checbox:column_checbox,
        	sys_menu_checbox:sys_menu_checbox,
        	area_hidden_ids:area_hidden_ids,
            company_id: company_id,
			role_list: role_list,
        	admin_id:admin_id},function(result){
				if(result == '1'){
					var msg = '编辑成功';
				}else if(result == 2){
                	var msg = '请选择所属公司';
            	}else{
					var msg = '编辑失败';
				}

				parent.layer.msg(msg,{time:2000},1,function(a){

				});
				setTimeout(function(){
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					parent.layer.close(index);
				}, 1000);
          });
    });
    $("#ajaxback").click(function(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
    });
});
</script>
</body>
</html>